<template>
  <!-- 查询条件不能太多 模拟只有三四个的那种 -->
  <div class="setFlex commonSearch">
    <div>
      <form-show v-model="queryForm" :formConfig="formConfig" />
    </div>
    <div class="commonSearchButoon">
      <el-button type="primary" @click="() => searchMethod()">
        查询
      </el-button>
      <el-button size="normal" @click="() => resetSearch()">
        重置
      </el-button>
    </div>

  </div>
</template>
  

<script setup>

import { defineProps, onMounted, reactive, defineEmits } from 'vue'; //获取父组件传的props和向父组件发送方法
import FormShow from './Form/index.vue'

// 获取父组件的传参
const props = defineProps({
  formConfig: {
    type: Object,
    default: () => {
      return {}
    }
  },
});
const emits = defineEmits(['searchMethodParent']);



const queryForm = reactive({});

onMounted(() => {
  props.formConfig.formItemList.map(item => {
    queryForm[item.key] = item.defaultSearch || ''
  })
  searchMethod()
})

const searchMethod = () => {
  emits('searchMethodParent', queryForm)
}
const resetSearch = () => {
  props.formConfig.formItemList.map(item => {
    queryForm[item.key] = ''
  })
  searchMethod()
}
</script>
<style lang="less" scoped>
.setFlex {
  display: flex;
}

/deep/ .el-form--inline .el-form-item {
  margin-right: 18px !important;

  .el-input {
    width: 180px !important;
  }
  .el-select{
    width: 180px !important;
  }
}

</style>
  